<template>
    <master title="谷阳">
        <div class="base1">
            hello world
        </div>
    </master>
</template>
<script type="text/javascript">
    (function (G) {
        G.vue({
            "usingComponents": {//引入组件
                "master": "/components/Master/Master",//母版组件
                "mixinput": "/components/Input/Mixinput/Mixinput"
            },
            "enablePullDownRefresh": true
        }, {
            data: {
                users: null,
                deleteData: null,
                dialogVisible: false,
                isAdd: true,
                dataFormat: 'yyyy-MM-dd',
                timeFormat: 'HH:mm:ss',
                formLabelWidth: '100px',
                form: {},
                // 1日常巡查/2月度考核/3安全巡查/4重大环卫设施巡查/5广告巡查/6农村环卫巡查
                patroltypes: [{
                    value: '1',
                    label: '日常巡查'
                }, {
                    value: '2',
                    label: '月度考核'
                }, {
                    value: '3',
                    label: '安全巡查'
                }, {
                    value: '4',
                    label: '重大环卫设施巡查'
                }, {
                    value: '5',
                    label: '广告巡查'
                }, {
                    value: '6',
                    label: '农村环卫巡查'
                }],
                dialogFormVisible: false, // 打开编辑新增页面
                tableData: [],
                total: 0,
                params: {
                    pageNum: 1,
                    pageSize: 10,
                },
                // 地图
                longitude: null,
                latitude: null,
                address: null,
                inventoryId: null,
                inventorys: null,
                unitId: null,
                grids: null,
            },
            methods: {
                getGrids() {
                    G.get('{JAVAURL}/patrol/getGrids')
                        .then((res) => {
                            console.log('-----log1', res);
                            this.grids = res.data
                        });
                },
                mapchange(cont) {
                    console.log('---form.latLonArray', this.form.latLonArray);
                    console.log('---detail', cont.detail);
                    console.log('---latitude', cont.detail.latitude);
                    console.log('---longitude', cont.detail.longitude);
                    this.longitude = cont.detail.longitude
                    this.latitude = cont.detail.latitude
                    this.address = cont.detail.address
                    this.form.latLonArray = cont.detail.value
                    this.inventoryId = cont.detail.facilityId
                    this.inventorys = []
                    this.unitId = cont.detail.unitId
                    if (!this.inventoryId) {
                        G.get('/v1/map/getLoctionInfo', {
                            longitude: this.longitude,
                            latitude: this.latitude
                        }).then(ree => {
                            if (!ree.errorMsg) {
                                this.inventorys = ree
                            }
                        })
                    }
                },
                handleClose() {
                    console.log('handleClose');
                    this.dialogVisible = false
                },
                deleteComfirm() {
                    G.post('{JAVAURL}/patrol/deletePlan', this.deleteData)
                        .then((res) => {
                            console.log('-----log', res);
                            this.dialogFormVisible = false
                            this.getData()
                        });
                    this.dialogVisible = false
                },
                commit() {
                    console.log('========1');
                    this.isAdd === true ? this.addPlan() : this.updatePlan()
                },
                uncommit() {
                    console.log('========2');
                    this.dialogFormVisible = false
                    // this.getData()
                },
                updatePlan() {
                    G.post('{JAVAURL}/patrol/updatePlan', this.form)
                        .then((res) => {
                            console.log('-----log', res);
                            this.dialogFormVisible = false
                            this.getData()
                        });
                },
                addPlan() {
                    G.post('{JAVAURL}/patrol/addPlan', this.form)
                        .then((res) => {
                            console.log('-----log', res);
                            this.dialogFormVisible = false
                            this.getData()
                        });
                },
                deletePlan(row) {
                    console.log('----row', row);
                    this.deleteData = row
                    this.dialogVisible = true
                },
                showAddDialog(row) {
                    console.log('----row', row);
                    this.form = row ?? {}
                    if (row) {
                        this.isAdd = false
                    } else {
                        this.isAdd = true
                    }
                    this.dialogFormVisible = true
                },
                getAllUsers() {
                    G.get('{JAVAURL}/patrol/getUsers')
                        .then((res) => {
                            this.users = res.data
                            console.log('-----log', this.users);
                        });
                },
                handleSizeChange(val) {
                    console.log(`每页 ${val} 条`);
                    this.params.pageSize = val
                    this.getData()
                },
                handleCurrentChange(val) {
                    console.log(`当前页: ${val}`);
                    this.params.pageNum = val
                    this.getData()
                },
                // searchBut() {
                //     console.log('-----searchBut', this.params);
                //     this.getData();
                // },
                getData() {
                    this.header = {
                        'token': G.Storage.get('userInfo').token
                    };
                    G.post('{JAVAURL}/patrol/planWithUserName', this.params)
                        .then((res) => {
                            console.log('-----log', res);
                            this.tableData = res.data.records
                            this.total = res.data.total
                        });
                },
            },
            mounted() {
                // this.getGrids()
                // this.getAllUsers()
                // this.getData()
            }
        });
    })(Y)
</script>
<style scoped>
    .base1 {
        display: flex;
        flex-direction: column;
        width: 95%;
        padding: 20px;
    }

    .top1 {
        display: flex;
        width: 100%;
        padding: 20px;
    }

    .flex1 {
        flex: 1;
    }

    .body1 {
        width: 100%;
        padding: 20px;
    }

    .table1 {
        display: flex;
        padding: 10px;
    }

    .caozuo1 {
        /* flex: 1; */
        margin-left: 5px;
        /* margin-right: 5px; */
    }

    .searchinput {
        width: 200px;
        margin-right: 20px;
    }

    .inputWidth {
        width: 200px;
    }

    .addPlan {
        display: flex;
        flex-wrap: wrap;
    }

    .startTimeWidth {
        width: 500px;
    }
</style>